package com.aier.classes.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.aier.classes.entity.ClassPhoto;
import com.aier.classes.entity.ClassPhotoImg;
import com.aier.classes.entity.ClassPhotoType;
import com.aier.classes.entity.ClassTeacher;
import com.aier.classes.entity.Classes;
import com.aier.classes.service.IClassService;
import com.aier.classes.service.IClassUserService;
import com.aier.common.common.CommonSession;
import com.aier.school.entity.SchoolMessage;

@Scope("prototype")
@Component("classesHomePageAction")
public class ClassesHomePageAction extends ClassesBaseAction{

    /**
     * 班级主页及其相关子页面
     */
    private static final long serialVersionUID = 1L;
    

    @Resource(name = "classService")
    private IClassService classService;    
    @Resource(name = "classUserService")
    private IClassUserService classUserService;        
    
    private int s;                //成功:1 ,失败:0
    private String error_info;    //错误提示信息
    
    private List<SchoolMessage> classMessageList;    //班级公告列表
    private List<ClassPhoto> classPhotoList;        //班级相册列表
    
    private Classes classes;    //班级
    private Long cid;            //班级id
    private Long tid;            //教师id
    private Long cpid;            //班级相册图片id
    
    private int page;            //页数
    private int page_size;        //每页的记录数
    private int page_count;        //总页数
    private int count;            //总数
    
    
    private ClassPhotoType cpt; // 班级相册
    private List<ClassPhotoImg> cpiList; // (班级相册图片)列表
    private Long cptid;   // 相册id
    
    @Override
    public String execute(){
        classes = classService.searchClassById(cid);
        classPhotoList = classService.searchClassPhotoList(cid);
        
        cpt = classService.searchClassPhotoType(cptid);
        cpiList = classService.searchClassPhotoImgList(cptid);
        
        return SUCCESS;
    }    

    //进入班级管理的判断
    public String isClassAdmin(){
        Long uid = (Long) session.get(CommonSession.SESSION_ACCOUNT_ID);
        ClassTeacher classTeacher = classUserService.searchClassTeacherByIds(uid,cid);
        s = 0;
        if(classTeacher!=null&&(classTeacher.getIsadmin()==(short)1)){
            s = 1;
            tid = classTeacher.getTid();
        }
        return SUCCESS;
    }
    
    //删除班级相册图片
    public String deleteClassPhoto(){
        s = classService.deleteClassPhoto(cpid);
        return SUCCESS;
    }
    
    
    
    
    public Long getCid() {
        return cid;
    }

    public void setCid(Long cid) {
        this.cid = cid;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getPage_size() {
        return page_size;
    }

    public void setPage_size(int page_size) {
        this.page_size = page_size;
    }

    public int getPage_count() {
        return page_count;
    }

    public void setPage_count(int page_count) {
        this.page_count = page_count;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public int getS() {
        return s;
    }

    public String getError_info() {
        return error_info;
    }

    public List<SchoolMessage> getClassMessageList() {
        return classMessageList;
    }

    public Classes getClasses() {
        return classes;
    }

    public Long getTid() {
        return tid;
    }

    public void setClassService(IClassService classService) {
        this.classService = classService;
    }

    public void setClassUserService(IClassUserService classUserService) {
        this.classUserService = classUserService;
    }

    public List<ClassPhoto> getClassPhotoList() {
        return classPhotoList;
    }

    public void setCpid(Long cpid) {
        this.cpid = cpid;
    }

    public ClassPhotoType getCpt() {
        return cpt;
    }

    public List<ClassPhotoImg> getCpiList() {
        return cpiList;
    }

    public void setCptid(Long cptid) {
        this.cptid = cptid;
    }
    
    
    
}
